// pages/exercise/exercise.js
import request from '../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  
  data: {
      course:[{storeName: '',courseName: '',number: '',coachName:''}],
      coach:[{storeName1: '',coachName1: '',number1: ''}],
      vip:[{storeName2: '',number2: '',vtype:''}],
      tabindex:0,
      change:0,
      indexTitle:[{info:"课程订单"},{info:"教练订单"},{info:"会员订单"}]
  },
  openIndex(e){
    this.setData({
      change:e.target.dataset.id
    })
    console.log(e.target.dataset.id)
    this.getInfo(e.target.dataset.id)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getInfo(0),
    this.getCoachInfo(1),
    this.getVipInfo(2)
  },

  getInfo(status) {
    request({
      url: '/order/courseOrder?status=' + status,
      method: 'GET',
    }).then(res => {
      if (res.code === 200) {
        let courseData = res.data;
        this.setData({
          courseData:courseData
        })
        console.log(courseData);
      } else {
        wx.showToast({
          icon: 'error',
          // title: res,
        })
      }
    }).catch(err => {
      console.error(err);
    });
  },

  getVipInfo(status) {
    request({
      url: '/order/vipOrder?status=' + status,
      method: 'GET',
    }).then(res => {
      if (res.code === 200) {
        let vipData = res.data;
        this.setData({
          vipData:vipData
        })
        console.log(vipData)
      } else {
        wx.showToast({
          icon: 'error',
          title: res.message,
        })
      }
    }).catch(err => {
      console.error(err);
    });
  },

  getCoachInfo(status) {
    request({
      url: '/order/coachOrder?status=' + status,
      method: 'GET',
    }).then(res => {
      if (res.code === 200) {
        let coachData = res.data;
        this.setData({
          coachData:coachData
        })
        console.log(coachData);
      } else {
        wx.showToast({
          icon: 'error',
          title: res.message,
        })
      }
    }).catch(err => {
      console.error(err);
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})